﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 参数的验证
{
    public class 方法输入参数的验证优化
    {
        public static BaseResponse Demo(Student req)
        {
            BaseResponse resp = new BaseResponse();
            if (req.Age <= 0)
            {
                resp.Flag = false;
                resp.ErrorMsg = "员工年龄不能小于0";
                return resp;
            }
            if (req.Age > 200)
            {
                resp.Flag = false;
                resp.ErrorMsg = "员工年龄不能大于200";
                return resp;
            }
            return resp;
        }

        public static BaseResponse Demo优化(Student req)
        {
            if (req.Age <= 0)
            {
                return new BaseResponse("员工年龄不能小于0");
            }
            if (req.Age > 200)
            {
                return new BaseResponse("员工年龄不能大于200");
            }
            BaseResponse resp = new BaseResponse();

            return resp;
        }




    }

    public class Student
    {
        public int Age { get; set; }
        public int Gender { get; set; }
        public string Name { get; set; }
        public string IdCard { get; set; }
    }


    public class BaseResponse
    {
        public BaseResponse()
        {

        }

        public BaseResponse(string ErrorMsg = "")
        {
            this.Flag = false;
            this.ErrorMsg = ErrorMsg;
        }

        public string ErrorMsg { get; set; }
        public bool Flag { get; set; }
    }


}
